{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "from six.moves import cPickle as pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test data shape  (160, 160)\n",
      "test labels shape  (160, 2)\n"
     ]
    }
   ],
   "source": [
    "#Load test data and test labels\n",
    "pickle_file = 'data_saved.pickle'\n",
    "with open(pickle_file, 'rb') as f :\n",
    "    save = pickle.load(f)\n",
    "    test_data = save['test_data']\n",
    "    test_labels = save['test_labels']\n",
    "    del save  # hint to help gc free up memory\n",
    "print('test data shape ', test_data.shape)\n",
    "print('test labels shape ', test_labels.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Evaluating...\n",
      "\n",
      "INFO:tensorflow:Restoring parameters from /Users/MacBook/Documents/MLTraining/DECEPTIVE_REVIEWS_ON_HOTEL/runs/1503225456/checkpoints/model-2000\n",
      "The test accuracy is  0.8\n"
     ]
    }
   ],
   "source": [
    "print(\"\\nEvaluating...\\n\")\n",
    "\n",
    "# Evaluation\n",
    "# ==================================================\n",
    "CHECKPOINT_DIR='/Users/MacBook/Documents/MLTraining/DECEPTIVE_REVIEWS_ON_HOTEL/runs/1503225456/checkpoints/'\n",
    "checkpoint_file= tf.train.latest_checkpoint(CHECKPOINT_DIR)\n",
    "graph = tf.Graph()\n",
    "with graph.as_default():\n",
    "    sess = tf.Session()\n",
    "    with sess.as_default():\n",
    "        # Load the saved meta graph and restore variables\n",
    "        saver = tf.train.import_meta_graph(\"{}.meta\".format(checkpoint_file))\n",
    "        saver.restore(sess, checkpoint_file)\n",
    "        \n",
    "        # Get the placeholders from the graph by name\n",
    "        input_x = graph.get_operation_by_name(\"input_x\").outputs[0]\n",
    "        input_y = graph.get_operation_by_name(\"input_y\").outputs[0]\n",
    "        dropout_keep_prob = graph.get_operation_by_name(\"dropout_keep_prob\").outputs[0]\n",
    "        input_size = graph.get_operation_by_name(\"input_size\").outputs[0]\n",
    "        \n",
    "        # Tensors we want to evaluate\n",
    "        accuracy = graph.get_operation_by_name(\"accuracy/accuracy\").outputs[0]\n",
    "        \n",
    "        #Compute the accuracy on the test data\n",
    "        acc = sess.run(accuracy, {input_x:test_data, input_y:test_labels, dropout_keep_prob:1.0, input_size:test_labels.shape[0]})\n",
    "        \n",
    "        print('The test accuracy is ', acc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
